package com.elitel.common.core.exception;


import com.elitel.common.core.log.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class GlobalException extends RuntimeException {
    private Integer code;

    private String data;
    public GlobalException(String message) {
        super(message);
        this.code = ResultCodeEnum.UNKNOWN_ERROR.getCode();
    }

    public GlobalException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public GlobalException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    public GlobalException(ResultCodeEnum resultCodeEnum, String messageData) {
        this.code = resultCodeEnum.getCode();
        this.data = messageData;
    }

    public String toString() {
        return "Exception{code=" + this.code + ", message=" + this.getMessage() + '}';
    }

    public Integer getCode() {
        return this.code;
    }

    public void setCode(final Integer code) {
        this.code = code;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof GlobalException)) {
            return false;
        } else {
            GlobalException other = (GlobalException) o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$code = this.getCode();
                Object other$code = other.getCode();
                if (this$code == null) {
                    if (other$code != null) {
                        return false;
                    }
                } else if (!this$code.equals(other$code)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof GlobalException;
    }

    public int hashCode() {
        int result = 1;
        Object $code = this.getCode();
        result = result * 59 + ($code == null ? 43 : $code.hashCode());
        return result;
    }
}